package com.csw.dangdang.service;

import com.csw.dangdang.dao.AdminDao;
import com.csw.dangdang.entity.Admin;
import com.csw.dangdang.util.MybatisUtil;

public class AdminServiceImpl implements AdminService {
	@Override
	public Admin queryBy(Admin admin) {
		try {
			AdminDao ud = MybatisUtil.getMapper(AdminDao.class);
			String username = admin.getUsername();
			Admin uu = ud.queryBy(username);
			if (uu == null) {
				throw new RuntimeException("用户不存在");
			}
			if (!uu.getPassword().equals(admin.getPassword())) {
				throw new RuntimeException("密码错误");
			}
			return uu;
		} catch (Exception e) {
			throw new RuntimeException(e.getMessage());
		} finally {
			MybatisUtil.close();
		}
	}
}
